import { CommonModel, ListResponse, PagerQuery } from '.'
import { authorizeRequest } from '../util/http'

export type CategoryListResponse = ListResponse<Category>
export interface Category extends CommonModel{
    name:string;
    desc:string;
    type:number;
    userId:number;
}
export const apiGetCategoryList = async (pager?:PagerQuery)=>{
    return (await authorizeRequest.get<CategoryListResponse>('v1/categories',{params:pager})).data
}
export interface CreateCategoryRequest {
    name:string;
    desc:string;
}
export const apiPostCategory = async (params:CreateCategoryRequest) => {
    return (await authorizeRequest.post<object>('v1/categories',params)).data
}
export interface UpdateCategoryRequest {
    id:number
    name:string;
    desc:string;
}
export const apiPutCategory = async (params:UpdateCategoryRequest) =>{
    return (await authorizeRequest.put<object>('v1/categories/'+params.id,params)).data
}
export interface DeleteCategoryRequest {
    id:number
}
export const apiDeleteCategory = async (params:DeleteCategoryRequest) =>{
    return (await authorizeRequest.delete<object>('v1/categories/'+params.id)).data
}